﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using MarsExplorerWebSite.Model;

namespace MarsExplorerWebSite.Functions
{
    public class getWeather : FunctionBase
    {
        private MarsExplorerEntities dbContext;
        public int turnID { get; set; }

        int _moon=0,_solar=0,_long=0;

        public getWeather(HttpContext context) : base(context)
        {
            InitializeProperties();
        }

        public override string Execute()
        {
            List<GamesEvent> t = (from x in dbContext.GamesEvents where x.GameTurn == turnID select x).ToList();
            if (t!=null)
            {
                foreach (GamesEvent ge in t)
                {
                    switch(ge.Route)
                    {
                    	case "M":
                            _moon = ge.EventID;
                            break;
                        case "S":
                            _solar = ge.EventID;
                            break;
                        case "L":
                            _long = ge.EventID;
                            break; 
                    }
                }
            }
            return _moon.ToString()+";"+_solar.ToString() + ";"+_long.ToString();
           

          
        }

        public override void InitializeProperties()
        {
            try
            {
                turnID = Convert.ToInt32(Parameters["turnid"]);
                dbContext = new MarsExplorerEntities();
            }
            catch (Exception e)
            {
                string message = "";
                #if DEBUG
                message += " : " + e.ToString();
                #endif
            }
        }
    }
}